<%--
功能：获取指定目录下的文章
--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ tag import="java.util.List" %>
<%@ tag import="java.util.ArrayList" %>
<%@ tag import="org.springframework.context.ApplicationContext" %>
<%@ tag import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ tag import="com.probiz.estore.catalog.service.ContentCategoryManager" %>
<%@ tag import="com.probiz.estore.content.service.ContentManager" %>
<%@ tag import="com.probiz.estore.common.model.catalog.ContentCategory" %>
<%@ tag import="com.probiz.estore.common.model.content.Content" %>
<%@ tag import="com.probiz.estore.content.model.ContentSearchCriteria" %>

<%@ attribute name="categoryId" type="java.lang.Integer" required="false" description="父目录id" %>
<%@ attribute name="categoryCode" type="java.lang.String" required="false" description="父目录categoryCode.如果categoryId无指定，则必须制定categoryCode" %>
<%@ attribute name="firstResult" type="java.lang.Integer" required="false" description="第一条记录起始序号，默认为0" %>
<%@ attribute name="maxResults" type="java.lang.Integer" required="false" description="最多获取记录条数" %>

<%@ attribute name="returnContentListName" type="java.lang.String" required="true" description="要返回的文章列表名称" %>
<%@ attribute name="returnContentCategoryName" type="java.lang.String" required="true" description="要返回的文章目录实体名称" %>

<%

	ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(session.getServletContext());
	ContentManager contentManager = (ContentManager) ctx.getBean("contentManager");
	ContentCategoryManager contentCategoryManager = (ContentCategoryManager) ctx.getBean("contentCategoryManager");
	ContentCategory contentCategory;
	if(null == categoryId){
		contentCategory = contentCategoryManager.getCategoryByCode(categoryCode);
	}else{
		contentCategory = contentCategoryManager.getById(categoryId);
	}
	if(null == contentCategory)return;
	if(null==firstResult)firstResult = 0;
	if(null==maxResults)maxResults = -1;
	ContentSearchCriteria contentSearchCriteria = new ContentSearchCriteria();
	contentSearchCriteria.setCategoryId(contentCategory.getCategoryId().toString());
	contentSearchCriteria.setStatus(new Short("1")); //前台显示的
	contentSearchCriteria.setOrderby(new Short("1")); //按sortOrder排序的
	try{
		List<Content> contentList = contentManager.getContentList(contentSearchCriteria,firstResult.intValue(),maxResults.intValue());
		
		request.setAttribute(returnContentListName,contentList);
		request.setAttribute(returnContentCategoryName,contentCategory);
	}catch(Exception e){
		e.printStackTrace();
	}
	
	
%>
<jsp:doBody />
